package com.example.mobile2021606137xzt0507;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private RadioGroup radioGroup;
    private RadioButton radioBtnSupplier1;
    private RadioButton radioBtnSupplier2;
    private RadioButton radioBtnSupplier3;
    private RadioButton radioBtnSupplier4;
    private Button btnSupplierSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);
        initView();
        btnSupplierSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               int radBtnId = radioGroup.getCheckedRadioButtonId();
                if(radBtnId != -1){
                    RadioButton radBtn = findViewById(radBtnId);
                    Intent intent = new Intent();
                    intent.putExtra("supplier",radBtn.getText().toString());
                    setResult(RESULT_OK,intent);
                    finish();
                }else {
                    new AlertDialog.Builder(SupplierActivity.this)
                            .setMessage("请选择供应商")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_Main_Title);
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        radioBtnSupplier1 = (RadioButton) findViewById(R.id.radio_btn_supplier1);
        radioBtnSupplier2 = (RadioButton) findViewById(R.id.radio_btn_supplier2);
        radioBtnSupplier3 = (RadioButton) findViewById(R.id.radio_btn_supplier3);
        radioBtnSupplier4 = (RadioButton) findViewById(R.id.radio_btn_supplier4);
        btnSupplierSubmit = (Button) findViewById(R.id.btn_supplier_submit);
    }
}